<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

/**
 * File htdocs/Aplication/Models/dbAccess.php ini berisi class DbAccess
 *
 * PHP version 5.3
 *
 * @category Models
 * @package  Htdocs/Aplication/Models
 * @author   dio ratar <dio.22ratar@gmail.com>
 * @license  serveworship
 * (http://en.wikipedia.org/wiki/Proprietary_software)
 * @link     http://www.servworship.dio22r.com/
 */

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Class Cons this class is contain a variable  for
 * database conection
 *
 * @category Models
 * @package  Htdocs/Aplication/Models
 * @author   dio ratar <dio.22ratar@gmail.com>
 * @license  serveworship
 * (http://en.wikipedia.org/wiki/Proprietary_software)
 * @link     http://www.servworship.dio22r.com/
 */

class Db_Access extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
		$this->load->database("default");
	}
	
	/**
	 * 
	 * Enter description here ...
	 * @param unknown_type $query
	 */
	public function execque($query, $isPrint = false)
	{
		$result = $this->db->query($query);

        if ($isPrint) {
           echo "<hr />Query :: " . $query . "<hr/>"; 
        }
        
		if ($result) {
             echo "Error " . $this->db->errno($result) . " : " . $this->db->error($result). "\n";
             die();
		}
		
		$arrResult = array();
		foreach ($result->result_array() as $row) {
			$arrResult[] = $row; 
		}
		return $arrResult;
	}

    public function escape_input($arrData)
    {
        $arrRes = array();
        
        foreach ($arrData as $key => $value) {
            $arrRes[$key] = $this->db->escape($value);
        }
        
        return $arrRes;
    }
    
    
    public function to_array($arrData)
    {
    	$arrRes = array();
    	foreach ($arrData->result_array() as $row) {
    		$arrRes[] = $row;
    	}
    	return $arrRes;
    }
}
